from django.db import models

# Create your models here.

from django.contrib.auth import get_user_model

User = get_user_model()

from music.models import *
from playlist.models import *

class UserComments(models.Model):
    user = models.ForeignKey(User, verbose_name='听歌用户', help_text='听歌用户', related_name='create_user')
    song = models.ForeignKey(OneMusicCreate, verbose_name='歌曲', help_text='歌曲')
    comments = models.TextField(default='', max_length=500, verbose_name='评论', help_text='评论')
    praise_user = models.ForeignKey(User, verbose_name='点赞用户', help_text='点赞评论的用户', blank=True, null=True)
    add_time = models.DateTimeField(auto_now=True, verbose_name='操作的时间', help_text='操作的时间')
    reply_to = models.ForeignKey('self', verbose_name='回复某个评论', help_text='回复某个评论', null=True, default=None)

    class Meta:
        verbose_name_plural = verbose_name = '用户评论所听歌曲'

        permissions = (
            ('cannot_add_comments', '用户不能评论'),
            ('can_delete_comments', '可以删除评论'),
        )

    def __str__(self):
        return "评论:{},用户:{},歌曲:{},".format(self.comments, self.user.username, self.song.name)

class UserPraiseComments(models.Model):

    user = models.ForeignKey(User, verbose_name='点赞用户', help_text='点赞用户')
    comments = models.ForeignKey(UserComments, verbose_name='点赞评论', help_text='点赞评论')

    class Meta:
        verbose_name = '用户点赞一个评论'
        verbose_name_plural = verbose_name
        unique_together = ("user", "comments")